package com.cxs.plan.controller.bill;


import com.cxs.plan.domain.HttpResult;
import com.cxs.plan.domain.entity.PayType;
import com.cxs.plan.service.PayTypeService;
import com.cxs.plan.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bill/payType")
public class PayTypeController {

    @Autowired
    private PayTypeService payTypeService;

    @Autowired
    private PageUtil pageUtil;

    @GetMapping
    public HttpResult getPayTypeList(Integer type) {
        List<PayType> payTypeList = payTypeService.selectPayTypeList(type);
        return HttpResult.success(pageUtil.autoPage(payTypeList));
    }

    @PostMapping
    public HttpResult addPayType(@Validated @RequestBody PayType payType) {
        payTypeService.savePayType(payType);
        return HttpResult.success();
    }

    @GetMapping("/{id}")
    public HttpResult getPayTypeInfo(@PathVariable Long id) {
        return HttpResult.success(payTypeService.getById(id));

    }

    @PutMapping("/{id}")
    public HttpResult updatePayType(@PathVariable Integer id, @Validated @RequestBody PayType payType) {
        payType.setId(id);
        payTypeService.updateById(payType);
        return HttpResult.success();
    }

}
